function [ k, t ] = firwin( amiga_model, fs, fcut, len, prevent_shift )

if (sum(size(len) - [1 1]) == 0)
    L = len;
else
    L = size(len, 2);
end

k = sinc_gen(fs, fcut, L);

if (size(k, 2) > L)
    k = sinc_gen(fs, fcut, L);
end;

p = true;
if (nargin == 5)
    p = prevent_shift;
end

% prevent time shifting
if p
    if (mod(size(k, 2), 2) == 0)
        k = sinc_gen(fs, fcut, size(k, 2) - 1);
    end
end

% apply window
if strcmpi(amiga_model, 'a500') || strcmpi(amiga_model, 'a500 winuae')
    beta = 8;
elseif strcmpi(amiga_model, 'a1200') || ...
        strcmpi(amiga_model, 'a1200 winuae') || strcmpi(amiga_model, '')
    beta = 9;
else
    error('unsupported amiga model');
end
    
w = kaiser(size(k, 2), beta);
k = k .* w';

% normalize
k = k / trapz(k);

if (nargout == 2)
    t = linspace(0, (size(k, 2)-1)/fs, size(k, 2));
end

end